﻿using PoemGame.Domain.GameAggregate;
using PoemGame.Domain.PlayerAggregate;
using PoemGame.Domain.Seedwork;
using PoemGame.Domain.Services;

namespace PoemGame.ApplicationService
{
    /// <summary>
    /// 轮流答题
    /// </summary>
    public class GamePlayInturnService : GamePlayServiceBase, IDomainService
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_gameRepository"></param>
        /// <param name="_playerRepository"></param>
        /// <param name="_checkAnswerServiceFactory"></param>
        /// <param name="_aftergameActionFactory"></param>
        public GamePlayInturnService(
            IGameRepository _gameRepository,
            IPlayerRepository _playerRepository,
            IDomainServiceFactory<ICheckAnswerService> _checkAnswerServiceFactory)
            : base(_gameRepository, _playerRepository, _checkAnswerServiceFactory)
        {


        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="player"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        protected override async Task<string> SetNextPlayer(Player player, Game game)
        {
            var nextplayer = game.GetNextPlayer(player.Id);
            game.SetPlayerInturn(nextplayer.PlayerId);

            var nplayer = await playerRepository.GetPlayerByIdAsync(nextplayer.PlayerId);
            return $"轮到{nplayer.UserName}回答问题";
        }




        /// <summary>
        /// 轮流答题不需要在外部设置玩家,为了保持接口一致，返回成功
        /// </summary>
        /// <param name="player"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override Task<GeneralResult> SetPlayer(Player player, Game game)
        {
            return Task.FromResult(new GeneralResult { IsSuccess = true, Message = "" });
        }

       
    }
}
